package com.yiwei.jmx.view;

import android.app.Dialog;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Typeface;
import android.text.Spanned;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.allen.library.SuperButton;
import com.yiwei.jmx.R;
import com.yiwei.jmx.api.model.DealInfoModel;
import com.yiwei.jmx.util.DateTime;
import com.yiwei.jmx.util.Spans;
import com.yiwei.jmx.util.Util;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by xsooy-pc on 18-5-22.
 */

public class BorrowMoneyTipsDilaog extends Dialog {


    @BindView(R.id.btn_close)
    ImageView btnClose;
    @BindView(R.id.txt_tips)
    TextView txtTips;
    @BindView(R.id.txt_info_one)
    TextView txtInfoOne;
    @BindView(R.id.txt_info_one_right)
    TextView txtInfoOneRight;
    @BindView(R.id.txt_info_two)
    TextView txtInfoTwo;
    @BindView(R.id.txt_info_two_info)
    TextView txtInfoTwoInfo;
    @BindView(R.id.btn_submit)
    SuperButton btnSubmit;
    private Context context;


    public BorrowMoneyTipsDilaog(Context context) {
        this(context, R.style.DialogStyle);
    }

    public BorrowMoneyTipsDilaog(Context context, int themeResId) {
        super(context, themeResId);
        this.context = context;
        initView();
    }

    public void setData(DealInfoModel.DataBean data) {
//        txtTips.setText("注：如果提前还款，则仅收取借款之日起至实际还款之日的利息及服务费用；若逾期还款，将每日收取本金" + "2" + "%的违约金，同时还会影响到您的个人信用。");
        Spanned txt_one = Spans.with(context).font("借款金额", context.getResources().getDimensionPixelSize(R.dimen.x24), 0xff000000).
                font("\n" + DateTime.toDate(), context.getResources().getDimensionPixelSize(R.dimen.x20), 0xff566F8E).
                build();
        txtInfoOne.setText(txt_one);

        txtInfoOneRight.setText("￥" + data.money);

        Spanned txt_two = Spans.with(context).font("到期预还金额", context.getResources().getDimensionPixelSize(R.dimen.x24), 0xff000000).
                font("\n" + data.repay_date, context.getResources().getDimensionPixelSize(R.dimen.x20), 0xff566F8E).
                build();
        txtInfoTwo.setText(txt_two);


        Spanned txt_two_right = Spans.with(context).font("￥" + data.true_money, context.getResources().getDimensionPixelSize(R.dimen.x24), 0xff000000).
                font("\n本金" + data.money + "+利息" + data.money_fee, context.getResources().getDimensionPixelSize(R.dimen.x20), 0xff566F8E).
                build();
        txtInfoTwoInfo.setText(txt_two_right);

    }

    public void setBreakFee(String breakFee) {
        txtTips.setText("注：如果提前还款，则仅收取借款之日起至实际还款之日的利息及服务费用；若逾期还款，将每日收取本金" + breakFee + "%的违约金，同时还会影响到您的个人信用。");
    }

    private void initView() {
        setContentView(R.layout.dialog_borrow_money_tips);
        ButterKnife.bind(this);
        setCancelable(false);

        Window mWindow = getWindow();
        WindowManager.LayoutParams lp = mWindow.getAttributes();
        lp.width = Util.getDisplayMetrics(context).widthPixels;
        lp.gravity = Gravity.BOTTOM;
        if (context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {// 横屏
            lp.width = (int) (Util.getDisplayMetrics(context).heightPixels);
        } else {
            lp.width = (int) (Util.getDisplayMetrics(context).widthPixels);
        }
        mWindow.setAttributes(lp);


    }


    private OnChooseListener onChooseListener;

    public BorrowMoneyTipsDilaog setOnChooseListener(OnChooseListener onChooseListener) {
        this.onChooseListener = onChooseListener;
        return this;
    }

    @OnClick({R.id.btn_close, R.id.btn_submit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_close:
                dismiss();
                break;
            case R.id.btn_submit:
                dismiss();
                break;
        }
    }


    public interface OnChooseListener {
        void onSuccess();
    }
}
